<template>
  <div class="search-form">
    <el-form @submit.prevent="handleSubmit" :model="form" :rules="rules" ref="formRef">
      <div class="input-group">
        <el-input
          v-model="form.address"
          placeholder="输入Solana代币合约地址..."
          size="large"
          clearable
          :disabled="isLoading"
        />
        <el-button
          type="primary"
          size="large"
          @click="handleSubmit"
          :loading="isLoading"
          :disabled="!form.address.trim()"
        >
          {{ isLoading ? '查询中...' : '查询持有人' }}
        </el-button>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

// Props
const props = defineProps({
  isLoading: {
    type: Boolean,
    default: false
  }
})

// Emits
const emit = defineEmits(['search'])

// Reactive data
const form = ref({
  address: 'FoBeu5sdn91be9rCCf9uHnfHoGaZEqZnK6FGoNLxbonk'
})

const rules = ref({
  address: [
    { required: true, message: '请输入合约地址', trigger: 'blur' },
    { min: 32, message: '合约地址格式不正确', trigger: 'blur' }
  ]
})

// Methods
const handleSubmit = () => {
  if (!form.value.address.trim()) {
    ElMessage.error('请输入合约地址')
    return
  }
  
  if (form.value.address.length < 32) {
    ElMessage.error('合约地址格式不正确')
    return
  }
  
  emit('search', form.value.address.trim())
}
</script>

<style scoped>
.search-form {
  max-width: 800px;
  margin: 0 auto;
}

.input-group {
  display: flex;
  gap: 15px;
  align-items: center;
}

.input-group .el-input {
  flex: 1;
}

@media (max-width: 768px) {
  .input-group {
    flex-direction: column;
  }
  
  .input-group .el-button {
    width: 100%;
  }
}
</style>
